﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCM.UI.ChildWindows
{
    public partial class ImportChildWindow : EFViewCmes
    {
        public ImportChildWindow(String _dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(_dialogType);
        }
        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.ImportWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }
        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    base.Mode = OperationMode.Insert;
                    break;
                case "update":
                    base.Mode = OperationMode.Update;
                    break;
                default:
                    break;
            }
        }

     
        /// <summary>
        /// 确定
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Commit_Click(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick("ZMCMC0", "importMaterial", sender, e);
        }
        /// <summary>
        /// 取消
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }

        private void fdBusinessType_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            if (this.fdBusinessType.Value.Equals("回收"))
            {
                this.fdMaterialCode.IsReadOnly = true;
                this.fdMaterialName.IsReadOnly = true;
                this.fdSpecModel.IsReadOnly = true;
                this.fdImportNumber.IsReadOnly = true;
                this.fdImportNumber.Value = this.fdActualNumber.Value;
            }
            else
            {
                this.fdMaterialCode.IsReadOnly = false;
                this.fdMaterialName.IsReadOnly = false;
                this.fdSpecModel.IsReadOnly = false;
                this.fdImportNumber.IsReadOnly = false;
                this.fdImportNumber.Value = this.fdActualNumber.Value;
            }
        }
    }
}
